package com.qianbao.qianbaobusiness.ui.deposit;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.androidbase.utils.AndroidUtils;
import com.baseandroid.config.Global;
import com.baseandroid.mvp.BaseMvpActivity;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.MerchantInfo;
import com.qianbao.qianbaobusiness.json.UnPayShopListBean;
import com.qianbao.qianbaobusiness.ui.widget.DepositRecycleViewDivider;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

public class MyDepositActivity extends BaseMvpActivity<MyDepositView, MyDepositPresenter> implements MyDepositView{
    @BindView(R.id.toolbar_back)
    RelativeLayout toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.right_text)
    TextView rightText;
    @BindView(R.id.right_image)
    ImageView rightImage;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.recycleview)
    RecyclerView recycleview;

    private MyDepositAdapter  mAdapter;
    private UnPayShopListBean bean;
    private String            mMerchantNos;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mydeposit;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void setupView() {
        bean = (UnPayShopListBean) getIntent().getExtras().getSerializable("bean");
        toolbarTitle.setText(AndroidUtils.getContext().getResources().getString(R.string.my_deposit_title));
        initRecyclerView();
    }

    @Override
    protected void onResume() {
        getPresenter().getMerchantUnpayDepositInfo(getMerchantNos());
        super.onResume();
    }

    @Override
    protected void setupData(Bundle savedInstanceState) {

    }

    @OnClick({R.id.toolbar_back})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.toolbar_back:
                finish();
                break;
        }
    }

    private void initRecyclerView() {
        recycleview.addItemDecoration(new DepositRecycleViewDivider(
                this, LinearLayoutManager.HORIZONTAL, 2, ContextCompat.getColor(this, R.color.app_separator)));
        mAdapter = new MyDepositAdapter(this);
        recycleview.setLayoutManager(new LinearLayoutManager(this));
        recycleview.setAdapter(mAdapter);
        mAdapter.resetData(bean.getMerchantWaitPayInfo());
    }

    @Override
    public void getMerchantSuccess(UnPayShopListBean result) {
        mAdapter.resetData(result.getMerchantWaitPayInfo());
    }

    private String getMerchantNos() {
        String merchantNos = "";
        for (MerchantInfo merchantInfo : Global.getShopListInfo().merchantList) {
            if (TextUtils.isEmpty(merchantNos)) {
                merchantNos = merchantInfo.merchantNo;
            } else {
                merchantNos = merchantNos + "," + merchantInfo.merchantNo;
            }
        }
        return merchantNos;
    }
}
